package com.iwdnb.gkgz.ui.job;

import java.util.List;
import java.util.stream.Collectors;

import com.alibaba.fastjson.JSON;

import cn.hutool.core.date.DateUtil;
import com.google.common.collect.Lists;
import com.iwdnb.gkgz.application.service.StockPoolService;
import com.iwdnb.gkgz.common.model.dto.Stock;
import com.iwdnb.gkgz.common.model.dto.StockDayData;
import com.iwdnb.gkgz.common.utils.StockUtils;
import com.iwdnb.gkgz.infrastructure.dao.entity.StockPoolDO;
import com.iwdnb.gkgz.infrastructure.dao.repo.StockPoolRepository;
import com.iwdnb.job.annotation.Job;
import com.iwdnb.job.handler.BaseJobHandler;
import com.iwdnb.wwzy.dao.MetaDataDAO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 股票实时信息获取
 */
@Slf4j
@Job(cron = "*/5 * 9,10,11,13,14,15 * * ?")
public class StockRealtimeJob extends BaseJobHandler {

    @Autowired
    private StockPoolService stockPoolService;

    @Override
    public boolean doProcess(String parameter) {
        List<Stock> stockPoolDOS = stockPoolService.getStockList();
        if (CollectionUtils.isEmpty(stockPoolDOS)) {
            return true;
        }
        List<String> codes = stockPoolDOS.stream().map(stock -> stock.getMarket() + stock.getCode()).collect(
            Collectors.toList());
        List<StockDayData> stockDayDataList = StockUtils.getTodayStockData(codes);
        log.info(JSON.toJSONString(stockDayDataList));
        return true;
    }
}
